package com.example.demo.controller;

import com.example.demo.dao.entity.UserEntity;
import com.gitee.sunchenbin.mybatis.actable.command.BaseModel;
import com.gitee.sunchenbin.mybatis.actable.command.PageResultCommand;
import com.gitee.sunchenbin.mybatis.actable.manager.common.BaseCRUDManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
public class MysqlController {

    @Autowired
    private BaseCRUDManager baseCRUDManager;

    @RequestMapping("/select/user")
    public String select(HttpServletRequest request) {
        Object sss1 = request.getSession().getAttribute("sss");
        request.getSession(true).setAttribute("sss","111");
        UserEntity insert = baseCRUDManager.insert(UserEntity.builder().loginName("111").build());
        UserEntity insertSelective = baseCRUDManager.insertSelective(UserEntity.builder().id(10000L).loginName("222").build());
        List<UserEntity> userEntities1 = baseCRUDManager.selectAll(UserEntity.class);
        boolean b = baseCRUDManager.updateByPrimaryKey(UserEntity.builder().id(10000L).mobile("1111").build());
        boolean b1 = baseCRUDManager.updateByPrimaryKeySelective(UserEntity.builder().id(2L).mobile("1111").build());
        UserEntity userEntity = baseCRUDManager.selectOne(UserEntity.builder().id(1L).mobile("1111").build());
        UserEntity userEntity1 = baseCRUDManager.selectByPrimaryKey(UserEntity.builder().id(8L).mobile("1111").build());
        List<UserEntity> select = baseCRUDManager.select(UserEntity.builder().mobile("1111").build());
        int i = baseCRUDManager.selectCount(UserEntity.builder().build());
        int sss = baseCRUDManager.delete(UserEntity.builder().realName("sss").build());
        int i1 = baseCRUDManager.deleteByPrimaryKey(UserEntity.builder().id(5L).loginName("222").build());
        boolean b2 = baseCRUDManager.existsByPrimaryKey(UserEntity.builder().id(1L).build());
        boolean b3 = baseCRUDManager.existsByPrimaryKey(UserEntity.builder().id(222L).build());
        UserEntity user = new UserEntity();
        user.setCurrentPage(1);
        user.setPageSize(5);
        LinkedHashMap<String, String> ordermap = new LinkedHashMap<>();
        ordermap.put("id", BaseModel.ASC);
        user.setOrderBy(ordermap);
        PageResultCommand<UserEntity> search = baseCRUDManager.search(user);
        user.setCurrentPage(2);
        PageResultCommand<UserEntity> search2 = baseCRUDManager.search(user);
        PageResultCommand<UserEntity> search3 = baseCRUDManager.search(user, 1, 5, ordermap);
        return "success";//"insert:" + JSON.toJSONString(insert) + "<p> insertSelective:" + JSON.toJSONString(insertSelective) + "<p> selectAll:" + JSON.toJSONString(userEntities1) + "<p> updateByPrimaryKey:" + b + "<p> updateByPrimaryKeySelective:" + b1 + "<p> selectOne:" + JSON.toJSONString(userEntity) + "<p> selectByPrimaryKey:" + JSON.toJSONString(userEntity1) + "<p> select:" + JSON.toJSONString(select) + "<p> selectCount:" + i + "<p> delete:" + sss + "<p> deleteByPrimaryKey:" + i1 + "<p> b2:" + b2 + "<p> b3:" + b3+ "<p> search:" + JSON.toJSONString(search)+ "<p> search2:" + JSON.toJSONString(search2)+ "<p> search3:" + JSON.toJSONString(search3);
    }
}